#ifndef GLTEXTURE_H
#define GLTEXTURE_H

#include "ResourceData.h"

class GLTexture  : public CResourceData
{
public:

	// Enum identifying the texture type
	enum _TextureType
	{
		// 1D texture, used in combination with 1D texture coordinates
		TEX_TYPE_1D = 1 ,
		// 2D texture, used in combination with 2D texture coordinates (default)
		TEX_TYPE_2D = 2 ,
		/// 3D volume texture, used in combination with 3D texture coordinates
		TEX_TYPE_3D = 3 ,
		/// 3D cube map, used in combination with 3D texture coordinates
		TEX_TYPE_CUBE_MAP = 4
	};
	typedef enum _TextureType TextureType;

	
public:
	
	unsigned int texture[1];						// OpenGL's number for the texture
	int  m_nWidth;									// Texture's width
	int  m_nHeight;									// Texture's height
	bool m_bMipmap;
	
	// texture type
	TextureType m_eTextureType;
	
	void Use();										 // Binds the texture for use
	void UnUse();                                    // unbinds the texture for use
    void FreeInternalResourcesImpl(void);


	// Sets the type of texture; can only be changed before load() 
	virtual void SetTextureType( TextureType eType ) { m_eTextureType = eType; }
	
	// Gets the type of texture 
	virtual TextureType GetTextureType( void ) const { return m_eTextureType; }


	GLTexture(CResourceManager* pCreator,ResourceHandle hResource,char* name = 0,char* path = 0) : CResourceData(pCreator,hResource,name,path)
	{
		texture[0] = 0;
		m_nWidth   = 0;
		m_nHeight  = 0;
		m_bMipmap  = false;
	}
	
	virtual ~GLTexture()
	{  FreeInternalResourcesImpl();
	}
};


class TexturePtr : public CMSmartPtr<GLTexture>
{
public:
	TexturePtr() : CMSmartPtr<GLTexture>() {}

	explicit TexturePtr(GLTexture* rep)   
		: CMSmartPtr<GLTexture>(rep) {}

	TexturePtr(const TexturePtr& ptr)     
		: CMSmartPtr<GLTexture>(ptr) {}

	TexturePtr(const ResourcePtr& ptr)     
		: CMSmartPtr<GLTexture>()
	{
		m_pObject = static_cast<GLTexture*> (ptr.get());

		if(m_pObject)
		m_pObject->IncRefCount();
	}

	inline TexturePtr& operator=(const ResourcePtr& ptr)
	{
		if (m_pObject != ptr)
		{
			processDec();

			m_pObject = static_cast<GLTexture*> (ptr.get());

			if (m_pObject)
			m_pObject->IncRefCount();
		}

		return *this;
	}

};


#endif 